import request from '../../utils/request';

// 商品管理相关 API

// 新增商品
export const createProduct = (data: any) => {
    return request({
        url: '/product/api',
        method: 'post',
        data
    });
};

// 获取商品详情
export const getProductDetail = (id: string) => {
    return request({
        url: `/product/api/${id}`,
        method: 'get'
    });
};

// 更新商品
export const updateProduct = (id: string, data: any) => {
    return request({
        url: `/product/api/${id}`,
        method: 'put',
        data
    });
};

// 删除商品
export const deleteProduct = (id: string) => {
    return request({
        url: `/product/api/${id}`,
        method: 'delete'
    });
};

// 设置商品精选状态
export const setProductFeaturedStatus = (id: string, data: any) => {
    return request({
        url: `/product/api/${id}/featured`,
        method: 'put',
        data
    });
};

// 更新商品销量
export const updateProductSales = (id: string, data: any) => {
    return request({
        url: `/product/api/${id}/sales`,
        method: 'put',
        data
    });
};

// 获取审核通过的产品列表
export const getApprovedProductList = (params?: any) => {
    return request({
        url: '/product/api/approved',
        method: 'get',
        params
    });
};

// 审核产品
export const auditProduct = (data: any) => {
    return request({
        url: '/product/api/audit',
        method: 'post',
        data
    });
};

// 批量设置商品精选状态
export const batchSetProductFeaturedStatus = (data: any) => {
    return request({
        url: '/product/api/batch/featured',
        method: 'put',
        data
    });
};

// 根据分类获取商品列表
export const getProductsByCategory = (categoryId: string, params?: any) => {
    return request({
        url: `/product/api/category/${categoryId}`,
        method: 'get',
        params
    });
};

// 获取热销商品
export const getHotProducts = (params?: any) => {
    return request({
        url: '/product/api/hot',
        method: 'get',
        params
    });
};

// 获取新品
export const getNewProducts = (params?: any) => {
    return request({
        url: '/product/api/new',
        method: 'get',
        params
    });
};

// 分页查询商品列表
export const getProductPage = (params: any) => {
    return request({
        url: '/product/api/page',
        method: 'get',
        params
    });
};

// 分页查询待审核产品列表
export const getPendingAuditProductPage = (params: any) => {
    return request({
        url: '/product/api/pending-audit/page',
        method: 'get',
        params
    });
};

// 获取推荐商品
export const getRecommendedProducts = (params?: any) => {
    return request({
        url: '/product/api/recommend',
        method: 'get',
        params
    });
};

// 搜索商品
export const searchProducts = (params: any) => {
    return request({
        url: '/product/api/search',
        method: 'get',
        params
    });
};
